﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace SqlSugar_Geometry_Model.MyClass
{
    public class BaseClass
    {
        /// <summary>
        /// 将不缩进的 JSON 字符串转成缩进形式
        /// </summary>
        /// <param name="str">Json字符串</param>
        /// <returns></returns>
        public static string JsonIndentation(string str)
        {
            //string str = JsonConvert.SerializeObject(entity);
            JsonSerializer serializer = new JsonSerializer();
            TextReader tr = new StringReader(str);
            JsonTextReader jtr = new JsonTextReader(tr);
            object obj = serializer.Deserialize(jtr);
            if (obj != null)
            {
                StringWriter textWriter = new StringWriter();
                JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)
                {
                    Formatting = Formatting.Indented,
                    Indentation = 4,
                    IndentChar = ' '
                };
                serializer.Serialize(jsonWriter, obj);
                return textWriter.ToString();
            }
            else
            {
                return str;
            }
        }

        /// <summary>
        /// 产生随机小数
        /// </summary>
        /// <param name="ran">随机小数生成器</param>
        /// <param name="minValue">随机小数起始数</param>
        /// <param name="maxValue">随即小数终止数</param>
        /// <returns></returns>
        public static double RandomDouble(Random ran, double minValue, double maxValue)
        {
            return ran.NextDouble() * (maxValue - minValue) + minValue;
        }

        /// <summary>
        /// 产生随机整数
        /// </summary>
        /// <param name="ran">随机整数生成器</param>
        /// <param name="minValue">随机整数起始数</param>
        /// <param name="maxValue">随机整数终止数</param>
        /// <returns></returns>
        public static double RandomInt(Random ran, int minValue, int maxValue)
        {
            return ran.Next(minValue, maxValue + 1);
        }
    }
}